#include <stm8s_clk.h>

FlagStatus CLK_GetFlagStatus(CLK_Flag_TypeDef CLK_FLAG)
{
  uint16_t statusreg = 0;
  uint8_t tmpreg = 0;
  FlagStatus bitstatus = RESET;
  
  /* check the parameters */
  assert_param(IS_CLK_FLAG_OK(CLK_FLAG));
  
  /* Get the CLK register index */
  statusreg = (uint16_t)((uint16_t)CLK_FLAG & (uint16_t)0xFF00);
  
  
  if (statusreg == 0x0100) /* The flag to check is in ICKRregister */
  {
    tmpreg = CLK->ICKR;
  }
  else if (statusreg == 0x0200) /* The flag to check is in ECKRregister */
  {
    tmpreg = CLK->ECKR;
  }
  else if (statusreg == 0x0300) /* The flag to check is in SWIC register */
  {
    tmpreg = CLK->SWCR;
  }
  else if (statusreg == 0x0400) /* The flag to check is in CSS register */
  {
    tmpreg = CLK->CSSR;
  }
  else /* The flag to check is in CCO register */
  {
    tmpreg = CLK->CCOR;
  }
  
  if ((tmpreg & (uint8_t)CLK_FLAG) != (uint8_t)RESET)
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }
  
  /* Return the flag status */
  return((FlagStatus)bitstatus);
}

/**
  * @brief  Checks whether the specified CLK interrupt has is enabled or not.
  * @param   CLK_IT specifies the CLK interrupt.
  * can be one of the values of @ref CLK_IT_TypeDef
  * @retval ITStatus, new state of CLK_IT (SET or RESET).
  */
